<template>
  <el-container class="main_container">
    <!--头部布局-->
    <el-header>
      <!--logo和项目名称-->
      <div class="left_box">
        <img src="../assets/img/logo.jpg" alt="logo">
        <span>新冠物资管理系统</span>
      </div>
      <!--用户登录展示的头像-->
      <div class="right_box">
        <el-dropdown>
          <img src="../assets/img/avatar.jpg" alt="headImg">
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-house">系统首页</el-dropdown-item>
            <el-dropdown-item icon="el-icon-ship">交流讨论</el-dropdown-item>
            <el-dropdown-item icon="el-icon-switch-button">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse?'60px':'200px'">

        <!-- 展开/收起的效果 -->
        <div class="toggle_box" @click="toggleCollapse">|||</div>
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#001529"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
          :collapse-transition="false"
          :unique-opened="true"
           :router="true">
          <MenuTree :MenuList="this.MenuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main>
<!--        路由视图-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import MenuTree from "../components/MenuTree";
  export default {
    name: 'Main',
    components: {MenuTree},
    data: function () {
      return {
        isCollapse: false,
        MenuList:[
          {
            "id": 1,
            "parentId": 0,
            "menuName": "系统管理",
            "url": "",
            "icon": "el-icon-setting",
            "orderNum": 1,
            "open": 1,
            "disabled": false,
            "perms": null,
            "type": 0,
            "children": [
              {
                "id": 253,
                "parentId": 1,
                "menuName": "欢迎页面",
                "url": "/welcome",
                "icon": "el-icon-star-off",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": null,
                "type": 0,
                "children": []
              },
              {
                "id":4,
                "parentId":1,
                "menuName": "用户管理",
                "url": "/users",
                "icon":"el-icon-help",
                "or derNum":3,
                "open":0,
                "disabled":false,
                "perms":null,
                "type":0,
                "children":[]
              }
            ]
          }
        ]
      }
    },
    methods: {
      toggleCollapse () {
        this.isCollapse = !this.isCollapse
      }
    }
  }
</script>

<style lang="less" scoped>

  /* 头部布局 */
  .el-header {
    background-color: #001529;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    color: #FFFFFF;
    align-items: center;
    font-size: 20px;

    /* 左边的logo和名称 */

    .left_box {
      display: flex;
      align-items: center;

      /*logo*/

      img {
        width: 60px;
        height: 60px;
        margin: 10px 0 10px 10px;
      }

      /*名称*/

      span {
        margin-left: 15px;
      }
    }

    /* 右边登录头像 */

    .right_box {
      .el-dropdown > img {
        height: 60px;
        width: 60px;
        border-radius: 50%;
        background-color: #FFFFFF;
        margin: 0 15px 0 0;
        background-size: contain;
      }
    }

  }

  /* 侧菜单布局 */
  .el-aside {
    background-color: #001529;

    .el-menu {
      border-right: none;
    }


    /* 展开收起 */

    .toggle_box {
      background-color: #42b983;
      font-size: 15px;
      font-weight: bold;
      line-height: 24px;
      color: #FFFFFF;
      letter-spacing: 0.2em;
      text-align: center;
      cursor: pointer;
    }
  }

  /* 内容主体 */
  .el-main {
    background-color: #E9EEF3;
  }

  /* 自定义的容器布局 */
  .main_container {
    height: 100%;
  }


  /*下拉菜单的样式*/
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }

</style>
